<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>缴费管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <link rel="stylesheet" href="/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend></legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">类型</label>
                            <div class="layui-input-block">
                                <select name="type" lay-verType="tips" lay-verify="required" required>
                                    <option value="-1">请选择类型</option>
                                    <option value="0">未缴费</option>
                                    <option value="1">已缴费</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn" lay-submit lay-filter="data-search-btn"><i
                                    class="layui-icon"></i> 搜 索
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container"></div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-confirm"
               {{(d.status=='1')?'style="cursor:not-allowed"':'lay-event="Parking"'}}>确认缴费</a>
        </script>

        <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
        <script src="/js/sessionTimout.js" charset="utf-8"></script>
        <script>
            layui.use(['form', 'table'], function () {
                var $ = layui.jquery,
                    form = layui.form,
                    table = layui.table;

                // 表格渲染
                table.render({
                    elem: '#currentTableId',
                    url: '/UserPaymentServlet?opt=list',
                    toolbar: '#toolbarDemo',
                    defaultToolbar: ['filter', 'exports', 'print', {
                        title: '提示',
                        layEvent: 'LAYTABLE_TIPS',
                        icon: 'layui-icon-tips'
                    }],
                    cols: [[
                        {field: 'id', title: 'ID'},
                        {field: 'paymentname', title: '缴费名'},
                        {field: 'username', title: '用户名'},
                        {field: 'value', title: '缴费金额'},
                        {field: 'time', title: '缴费时间'},
                        {
                            field: 'status', title: '缴费状态', sort: true, templet: function (row) {
                                if (row.status == 1) {
                                    return '<input type="checkbox" lay-text="已缴费|未缴费" lay-skin="switch" checked disabled>'
                                } else {
                                    return '<input type="checkbox" lay-text="已缴费|未缴费" lay-skin="switch" disabled>'
                                }
                            }
                        },
                        {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
                    ]],
                    limits: [5, 10, 15, 20, 50],
                    limit: 10,
                    page: true,
                    skin: 'line'
                });

                // 监听搜索操作
                form.on('submit(data-search-btn)', function (data) {  // data 表单数据对象 name键 value值
                    //执行搜索重载
                    table.reload('currentTableId', {
                        page: {
                            curr: 1
                        }
                        , where: {
                            name: data.field.name
                        }
                    }, 'data');
                    return false;
                });
                // 监听确认
                table.on('tool(currentTableFilter)', function (obj) {
                    var data = obj.data;

                    layer.confirm(`确定要缴费吗?`, function (index) {
                        $.getJSON('/UserPaymentServlet?opt=confirm', `id=\${data.id}`, function (data) {
                            if (data.code == 0) {
                                layer.close(index);
                                layer.msg(data.msg, {icon: 1});
                                // 刷新数据
                                table.reload('currentTableId')
                            } else {
                                layer.msg(data.msg, {icon: 2});
                            }
                        })

                    });

                });


            });
        </script>
    </div>
</div>
</body>
</html>